Passed
Pull Request — master (#126)
by Kiran
04:13
created

$(document).ready   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 62

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 62
rs 9.4743
c 0
b 0
f 0

6 Functions

Rating   Name   Duplication   Size   Complexity  
A 0 9 1
A 0 10 1
A 0 14 2
A 0 7 1
A 0 8 1
A 0 6 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var WPInv_Admin;
2
jQuery(document).ready(function($) {
3
    var WPInv_Recurring = {
4
        init: function() {
5
            //Recurring select field conditionals
6
            this.edit_product_id();
7
            this.edit_profile_id();
8
            this.edit_txn_id();
9
            this.delete();
10
        },
11
        /**
12
         * Edit Subscription Text Input
13
         */
14
        edit_subscription_input: function(link, input) {
15
            //User clicks edit
16
            if (link.text() === WPInv_Admin.action_edit) {
0 ignored issues
show
Bug introduced by
The variable WPInv_Admin seems to be never initialized.
Loading history...
17
                //Preserve current value
18
                link.data('current-value', input.val());
19
                //Update text to 'cancel'
20
                link.text(WPInv_Admin.action_cancel);
21
            } else {
22
                //User clicked cancel, return previous value
23
                input.val(link.data('current-value'));
24
                //Update link text back to 'edit'
25
                link.text(WPInv_Admin.action_edit);
26
            }
27
        },
28
        edit_profile_id: function() {
29
            $('.wpinv-edit-sub-profile-id').on('click', function(e) {
30
                e.preventDefault();
31
                var link = $(this);
32
                var profile_input = $('input.wpinv-sub-profile-id');
33
                WPInv_Recurring.edit_subscription_input(link, profile_input);
34
                $('.wpinv-sub-profile-id').toggle();
35
                $('#wpinv-sub-profile-id-update-notice').slideToggle();
36
            });
37
        },
38
        edit_product_id: function() {
39
            $('.wpinv-sub-product-id').on('change', function(e) {
40
                e.preventDefault();
41
                $('#wpinv-sub-product-update-notice').slideDown();
42
            });
43
        },
44
        edit_txn_id: function() {
45
            $('.wpinv-edit-sub-transaction-id').on('click', function(e) {
46
                e.preventDefault();
47
                var link = $(this);
48
                var txn_input = $('input.wpinv-sub-transaction-id');
49
                WPInv_Recurring.edit_subscription_input(link, txn_input);
50
                $('.wpinv-sub-transaction-id').toggle();
51
            });
52
        },
53
        delete: function() {
54
            $('.wpinv-delete-subscription').on('click', function(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
55
                if (confirm(WPInv_Admin.delete_subscription)) {
0 ignored issues
show
Bug introduced by
The variable WPInv_Admin seems to be never initialized.
Loading history...
56
                    return true;
57
                }
58
                return false;
59
            });
60
        }
61
    };
62
    WPInv_Recurring.init();
63
});